package logique.programme;


import java.util.Vector;

import logique.solution.Solution;
import logique.solution.Variable;

public class CombinaisonLineaire {

	private Vector<Terme> termes;

	public CombinaisonLineaire () {
		termes = new Vector<Terme>();
	}
	
	public void addTerme(Variable variable, double coeff) {
		if (termes != null) {
			termes.addElement(new Terme(coeff, variable));
		}
	}
	
	public void addTerme(Terme terme) {
		if (termes != null) {
			termes.addElement(terme);
		}
	}
	
	public Vector<Terme> getListeTermes() {
		return termes;
	}
	public Terme getTerme (int i) {
		return termes.get(i);
	}
	public double evaluer(Solution s) {
		double res = .0;
		for (Terme t : termes){
			res += t.evaluer(s);
		}
		return res;
	}
	
	public String toString () {
		if (termes != null && !termes.isEmpty()) {
			String str = null;
			for (Terme t : termes) {
				if (str == null) 
					str = t.toString();
				else
					str += " + " + t.toString();
			}
			return str;
		} else {
			return "";
		}
	}
	
	public void afficher () {
		boolean premier = true;
		if (termes != null && !termes.isEmpty()) {
			for (Terme t : termes) {
				if (premier) 
					System.out.print(t.toString());
				else
					System.out.print(" + " + t.toString());
				premier = false;
			}
		}
	}
	
}